<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/8
 * Time: 18:07
 */

namespace App\Http\Controllers\Admin;


use App\Http\Logics\Admin\TagLogic;
use App\Http\Traits\TagTrait;
use App\Http\Controllers\BaseController;
class TagController extends BaseController
{
    use TagTrait;
    public function createTag()
    {
        $name = $this->name;
        $parent_id = $this->parent_id;
        $is_radiobox = $this->is_radiobox;
        $data = [
            'name' => $name,
            'parent_id' => $parent_id,
            'is_radiobox' => $is_radiobox
        ];
        $response = TagLogic::createTag($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function getTagList()
    {
        $limit = $this->limit;
        $parent_id = $this->parent_id;
        $data = [
            'parent_id' => $parent_id,
            'limit' => $limit
        ];
        $response = TagLogic::getTagList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function deleteTag()
    {
        $tag_id = $this->tag_id;
        $data = [
            'tag_id' => $tag_id
        ];
        $response = TagLogic::deleteTag($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function updateTag()
    {
        $icon = $this->icon;
        $tag_id = $this->tag_id;
        $name = $this->name;
        $data = [
            'icon' => $icon,
            'tag_id' => $tag_id,
            'name' => $name
        ];
        $response = TagLogic::updateTag($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }


    /**
     * 上传城市封面
     * @return string
     */
    public function uploadIcon()
    {
        $icon_file = $this->icon_file;
        $data = [
            'icon_file' => $icon_file
        ];
        $response = TagLogic::uploadIcon($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}